package cn.itrip.auth.service;

import cn.itrip.auth.exception.RedisException;
import cn.itrip.auth.exception.TokenException;
import cn.itrip.auth.exception.TokenGenerateException;
import cn.itrip.auth.exception.TokenTimeProtectedException;
import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.beans.vo.ItripTokenVO;

import java.text.ParseException;

/**
 * @Author: jxm
 * @Description:Token接口
 * @Date: 2020/3/12 16:11
 * @Version: 1.0
 */
public interface TokenService {

    //两小时 (token保存在token的时长)
    int TOKEN_TIMEOUT = 2*60*60 ;//2*60*60
    //一小时
    int TOKEN_REPLACEMENT_PROTECTED_TIME = 60*60*1000; //60*60
    int TOKEN_DEPLA_TIME = 120; //两分钟
    /**
     * 生成Token
     * @param agent
     * @param user
     * @return
     * @throws Exception
     */
    public String generateToken(String agent, ItripUser user)throws Exception;
    public ItripTokenVO generateToken2(String agent, ItripUser user) throws Exception;

    /**
     * 保存token
     * @param token
     * @param user
     * @return
     * @throws Exception
     */
    public boolean saveToken(String token, ItripUser user)throws Exception;

    /**
     * 验证Token
     * @param token
     * @param agent
     * @return
     * @throws Exception
     */
    public boolean validateToken(String token, String agent) throws Exception;

    /**
     * 删除token
     * @param token
     * @throws Exception
     */
    public void deleteToken(String token) throws Exception;

    /**
     * 置换token
     * @param token
     * @param agent
     * @return
     * @throws Exception
     */
    public ItripTokenVO refreshToken(String token, String agent)
            throws TokenException, TokenTimeProtectedException,
            ParseException, TokenGenerateException, RedisException;
}
